package net.daum.webtoon.android.dto;

import java.util.ArrayList;
import java.util.Iterator;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class DTO_EpisodeToon extends JSonDataObjectBase {
//	{
	public String id;
	public String title;
	public String episodeTitle;
	public String viewType;
	public String artist;
	public String size;
	public String encryptUseYn;
	public ArrayList<DTO_EpisodeImage> images;

	public DTO_EpisodeToon(JSONObject aJsonObject) {
		Iterator<Object> iterator = aJsonObject.keys();

		while (iterator.hasNext()) {
			Object obj = iterator.next();
			if (obj.toString().equalsIgnoreCase("images")) {
				this.images = new ArrayList<DTO_EpisodeImage>();
				DTO_EpisodeImage lEpisodeImage = null;
				try {

					JSONArray lImages = aJsonObject.getJSONArray("images");

					for (int i = 0; i < lImages.length(); i++) {
						lEpisodeImage = new DTO_EpisodeImage(lImages.getJSONObject(i));
						this.images.add(lEpisodeImage);
					}

				} catch (JSONException e) {
					if (isDebug)
						e.printStackTrace();
				}

			} else {
				setMemberFiled(this, aJsonObject, obj.toString());
			}
		}

		printMembers();
		insertObjToDB();
	}

	class DTO_EpisodeImage extends JSonDataObjectBase {

		public String id;
		public String url;
		public String key;
		public String imageOrder;
		public String mediaType;
		public String width;
		public String height;

		public DTO_EpisodeImage(JSONObject aJsonObject) {

			printMembers();
			insertObjToDB();
		}
	}

}
